import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    shopcar: [],
  },
  getters: {},
  mutations: {
    add(state, val) {
      let flag = false;
      state.shopcar.forEach((i) => {
        if (i.spuId == val.spuId) {
          flag = true;
          i.store_nums++;
        }
      });

      if (flag == false) {
        state.shopcar.push(val);
      }
    },
    //添加购物车
    removeAll(state, val) {
      state.shopcar = state.shopcar.filter((i) => {
        return val.includes(i) == false;
      });
    },
    //选中删除
    del(state, index) {
      state.shopcar.splice(index, 1);
    },
  },
  actions: {},
  modules: {},
});
